package wxk.interview.serializable;

import java.io.*;

/**
 * @author wangxuekai
 * @version 2.2
 * @Date 2017/3/9.
 * @since 2.2
 */
public class PersonRepeat implements Serializable{

    private static final long serialVersionUID = 3436474299380633602L;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "PersonRepeat{" +
                "name='" + name + '\'' +
                '}';
    }

    public static void main(String[] args){
        PersonRepeat personRepeat = new PersonRepeat();
        personRepeat.setName("lpp");

        File file = new File("personRepeat.obj");

        try {
            ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
            outputStream.writeObject(personRepeat);
            outputStream.flush();
            System.out.println(file.length());


            ObjectInputStream inputStream1 = new ObjectInputStream(new FileInputStream(file));
            PersonRepeat o1 = (PersonRepeat) inputStream1.readObject();


            personRepeat.setName("22");
            outputStream.writeObject(personRepeat);
            outputStream.flush();
            System.out.println(file.length());

            outputStream.close();

            PersonRepeat o2 = (PersonRepeat) inputStream1.readObject();

            inputStream1.close();

            System.out.println(o1 == o2);
            System.out.println(o1+"----"+o2);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
